﻿using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;


namespace Web.Pages.QuShui.DiXiaS.ChaXunGL
{
    public partial class QuJianCX_DXS : BasePage
    {
        #region 属性
       

       


        private DataTable dtGridTab2_1
        {
            get
            {
                return ViewState["dtGridTab2_1"] as DataTable;
            }
            set
            {
                ViewState["dtGridTab2_1"] = value;
            }
        }

        private DataTable dtGridTab2_2
        {
            get
            {
                return ViewState["dtGridTab2_2"] as DataTable;
            }
            set
            {
                ViewState["dtGridTab2_2"] = value;
            }
        }
        /// <summary>
        /// //////////////////////////////////////////////////////////
        /// </summary>
      












        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();
        /// <summary>
        /// 行政区
        /// </summary>
        QS_JX_XINGZHENGQBLL XZQ = new QS_JX_XINGZHENGQBLL();
        /// <summary>
        /// 行业分类
        /// </summary>
        QS_JX_HANGYEFLXXBLL HYFL = new QS_JX_HANGYEFLXXBLL();
        /// <summary>
        /// 取水用途
        /// </summary>
        QS_JX_QUSHUIXXBLL QSYT = new QS_JX_QUSHUIXXBLL();
        /// <summary>
        /// 管理部门
        /// </summary>
        QS_JX_BUMENXXBLL GLBM = new QS_JX_BUMENXXBLL();
        /// <summary>
        /// 流域信息
        /// </summary>
        QS_JX_LIUYUXXBLL LYXX = new QS_JX_LIUYUXXBLL();
        /// <summary>
        /// 水利分片
        /// </summary>
        QS_JX_SHUILIFPXXBLL SLFP = new QS_JX_SHUILIFPXXBLL();
        /// <summary>
        /// 水资源分区
        /// </summary>
        QS_JX_SHUIZIYFQBLL SZYFQ = new QS_JX_SHUIZIYFQBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
            }
           
        }




        /// <summary>
        /// 查询信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnChaXun_Click(object sender, EventArgs e)
        {
            if (cmbYear.Value.ToString() != "")
            {
                LoadGridData();
                
            }
        }





        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            int wtype = 2;
          
            //水量年月
            string water_y_m = BusinessTool.GetSLYMorZWNY(1, wtype).ToString();
            for (int i = DateTime.Now.Year - 10; i <= DateTime.Now.Year; i++)
            {
                cmbYear.Items.Add(i.ToString(), i.ToString());
                cmbYear2.Items.Add(i.ToString(), i.ToString());
            }


            for (int i = 1; i <= 12; i++)
            {
                cmbMonth.Items.Add(i.ToString(), i.ToString());
                cmbMonth2.Items.Add(i.ToString(), i.ToString());
            }
           
            cmbYear.Value = Convert.ToInt32(water_y_m) / 100;
            cmbYear2.Value = Convert.ToInt32(water_y_m) / 100;
            cmbMonth.Value = 1;
            cmbMonth2.Value = Convert.ToInt32(water_y_m) % 100;
            //加载管理部门
            LoadGLBM();
            //加载行政区
            LoadXZQ();
            //加载业务员
            LoadYWY();
            //加载取水用途
            LoadQSYT();
            //加载行业分类
            LoadHYFL();
            //加载流域
            LoadLY();
            //水利分片
            LoadSLFP();
            //水资源分区
            LoadSZYFQ();
        }



        /// <summary>
        /// 加载管理部门
        /// </summary>
        private void LoadGLBM()
        {
            DataTable dt = GLBM.SelectQS_JX_BUMENXXesDynamic("I_JLZT=0 and S_BUMENBH NOT IN(0,600)", null);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cbmGuanLiBM.Items.Add(dt.Rows[i]["S_BUMENMC"].ToString(), dt.Rows[i]["S_BUMENBH"]);
            }
            cbmGuanLiBM.Items.Insert(0, new ListEditItem("", "0"));
        }

        /// <summary>
        /// 加载行政区
        /// </summary>
        private void LoadXZQ()
        {
            DataTable dt = XZQ.SelectQS_JX_XINGZHENGQsDynamic("I_JLZT=0", null);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbXingZhengQ.Items.Add(dt.Rows[i]["S_XINGZHENGQM"].ToString(), dt.Rows[i]["S_XINGZHENGQH"]);
            }
        }

        /// <summary>
        /// 加载业务员
        /// </summary>
        private void LoadYWY()
        {
            PageTools.QSLoadCombox(cmbYeWuY, PageTools.eLoadType.业务员QS, null, "");
        }


        /// <summary>
        /// 加载 取水用途
        /// </summary>
        private void LoadQSYT()
        {
            DataTable dt = QSYT.SelectQS_JX_QUSHUIXXesDynamic("I_JLZT=0", null);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbQuShuiYT.Items.Add(dt.Rows[i]["S_QUSHUIMC"].ToString(), dt.Rows[i]["S_QUSHUIBH"]);
            }
            cmbQuShuiYT.Items.Insert(0, new ListEditItem("", "-1"));
        }
        /// <summary>
        /// 加载行业分类
        /// </summary>
        private void LoadHYFL()
        {
            DataTable dt = HYFL.SelectQS_JX_HANGYEFLXXesDynamic("I_JLZT=0", "S_FENLEIBH");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbHangYeLX.Items.Add(dt.Rows[i]["S_FENLEIMC"].ToString(), dt.Rows[i]["S_FENLEIBH"]);
            }
            cmbHangYeLX.Items.Insert(0, new ListEditItem("", "0"));
        }

        /// <summary>
        /// 加载流域
        /// </summary>
        private void LoadLY()
        {
            DataTable dt = LYXX.SelectQS_JX_LIUYUXXesDynamic("I_JLZT=0", null);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbLiuYu.Items.Add(dt.Rows[i]["S_LIUYUMC"].ToString(), dt.Rows[i]["S_LIUYUBH"]);
            }
            cmbLiuYu.Items.Insert(0, new ListEditItem("", "0"));
        }

        /// <summary>
        /// 加载水利分片
        /// </summary>
        private void LoadSLFP()
        {
            DataTable dt = SLFP.SelectQS_JX_SHUILIFPXXesDynamic("I_JLZT=0", null);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbShuiLiFP.Items.Add(dt.Rows[i]["S_SHUILIFPMC"].ToString(), dt.Rows[i]["S_SHUILIFPBH"]);
            }
            cmbShuiLiFP.Items.Insert(0, new ListEditItem("", "0"));
        }

        /// <summary>
        /// 加载水资源分区
        /// </summary>
        private void LoadSZYFQ()
        {
            DataTable dt = SZYFQ.SelectQS_JX_SHUIZIYFQsDynamic("I_JLZT=0", null);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbShuiZiYFQ.Items.Add(dt.Rows[i]["S_SHUIZIYMC"].ToString(), dt.Rows[i]["S_SHUIZIYBH"]);
            }
            cmbShuiZiYFQ.Items.Insert(0, new ListEditItem("", "0"));
        }
        /// <summary>
        /// 加载查询数据
        /// </summary>
        private void LoadGridData()
        {
            int wtype = 2;
            BindQuanNian();
          

        }
        #region 全年情况查询

        private Dictionary<string, string> getConditions()
        {
            Dictionary<string, string> list = new Dictionary<string, string>();
            list.Add("y1", cmbYear.Value.ToString());
            list.Add("m1", this.cmbMonth.Value.ToString());
            list.Add("y2", cmbYear2.Value.ToString());
            list.Add("m2", this.cmbMonth2.Value.ToString());
            list.Add("xingzhengq", this.cmbXingZhengQ.SelectedIndex <= 0 ? null : Convert.ToString(this.cmbXingZhengQ.Value));
            list.Add("ywy", this.cmbYeWuY.SelectedIndex <= 0 ? null : cmbYeWuY.Value.ToString());
            list.Add("yhh", txtYongHuH.Text);
            list.Add("yhm", txtYongHuM.Text);
            list.Add("dizhi", txtYongHuDZ.Text);
            list.Add("bumen", cbmGuanLiBM.Value == null ? null : cbmGuanLiBM.Value.ToString());
            list.Add("shuijia", txtShuiJia.Text);
            list.Add("qushuiyt", cmbQuShuiYT.SelectedIndex <= 0 ? null : cmbQuShuiYT.Value.ToString());
            list.Add("hangyelx", cmbHangYeLX.SelectedIndex <= 0 ? null : cmbHangYeLX.Value.ToString());
            list.Add("huanxianbj", this.cmbHuanNeiHW.SelectedIndex <= 0 ? null : cmbHuanNeiHW.Value.ToString().Trim());
            list.Add("shoufeifs", this.cmbShouFeiFS.SelectedIndex <= 0 ? "-1" : Convert.ToString(rabShouFeiFS.Value));
            list.Add("kaihuhm", txtKaiHuHM.Text);
            list.Add("kaihuzh", txtYinHangZH.Text);
            list.Add("liuyu", this.cmbLiuYu.SelectedIndex <= 0 ? null : Convert.ToString(cmbLiuYu.Value));
            list.Add("shuiziyfq", this.cmbShuiZiYFQ.SelectedIndex <= 0 ? null : Convert.ToString(cmbShuiZiYFQ.Value));
            list.Add("shuilifp", this.cmbShuiLiFP.SelectedIndex <= 0 ? null : Convert.ToString(cmbShuiLiFP.Value));
            return list;
        }
        private void BindQuanNian()
        {
            DataTable dt = null;
            gvGrid1Tab2.Columns.Clear();
            Dictionary<string, string> clist = this.getConditions();

            dt = SearchSpHelper.P_QSCX_QUJIANCX_DXS(Convert.ToInt32(clist["y1"]),Convert.ToInt32(clist["m1"]),Convert.ToInt32(clist["y2"]),Convert.ToInt32(clist["m2"]), clist["xingzhengq"], clist["ywy"], clist["yhh"], clist["yhm"], clist["dizhi"], clist["bumen"], clist["shuijia"], clist["qushuiyt"], clist["hangyelx"], clist["huanxianbj"], Convert.ToInt32(clist["shoufeifs"]), clist["kaihuhm"], clist["kaihuzh"], clist["liuyu"], clist["shuiziyfq"], clist["shuilifp"]).Tables[0];
            LoadColumnDate(gvGrid1Tab2, "S_YONGHUH", "用户号", 80);
            LoadColumnDate(gvGrid1Tab2, "S_YONGHUM", "用户名", 200);
            LoadColumnDate(gvGrid1Tab2, "I1", "普通采", 90);
            LoadColumnDate(gvGrid1Tab2, "I2", "矿泉采", 90);
            LoadColumnDate(gvGrid1Tab2, "I3", "采灌采", 100);
            LoadColumnDate(gvGrid1Tab2, "I0", "开采量", 100);
            LoadColumnDate(gvGrid1Tab2, "J1", "采灌灌", 100);
            LoadColumnDate(gvGrid1Tab2, "J2", "专灌", 100);
            LoadColumnDate(gvGrid1Tab2, "J0", "回灌量", 120);
            LoadColumnDate(gvGrid1Tab2, "K0", "总水量", 100);
            LoadColumnDate(gvGrid1Tab2, "N0", "深井水费", 100, "0.00");
            LoadColumnDate(gvGrid1Tab2, "L1", "开采计划", 100);
            LoadColumnDate(gvGrid1Tab2, "L2", "采灌采计划", 100);
            LoadColumnDate(gvGrid1Tab2, "L3", "采灌灌计划", 100);

            LoadColumnDate(gvGrid1Tab2, "L4", "现计划", 100);
            LoadColumnDate(gvGrid1Tab2, "L5", "超计划", 100);
            LoadColumnDate(gvGrid1Tab2, "L6", "加价调整", 100);
            LoadColumnDate(gvGrid1Tab2, "L7", "加价", 100);
            LoadColumnDate(gvGrid1Tab2, "M3", "超计划金额", 100, "0.00");
            LoadColumnDate(gvGrid1Tab2, "M4", "加价额", 100, "0.00");
            LoadColumnDate(gvGrid1Tab2, "N0", "深井水费", 100, "0.00");
            LoadColumnDate(gvGrid1Tab2, "M1", "开采完成率", 100, "0.00");
            LoadColumnDate(gvGrid1Tab2, "M2", "回灌完成率", 100, "0.00");
            LoadColumnDate(gvGrid1Tab2, "M5", "超计划率", 100, "0.00");
            LoadColumnDate(gvGrid1Tab2, "M6", "加价", 100, "0.00");

            dtGridTab2_1 = dt;
            gvGrid1Tab2.DataSource = dtGridTab2_1;
            gvGrid1Tab2.DataBind();
            this.lsCountQN.InnerText = "共" + (dt.Rows.Count - 1).ToString() + "条数据";
            gvGrid1Tab2.FocusedRowIndex = 0;
            string yonghuh = Convert.ToString(this.gvGrid1Tab2.GetRowValues(this.gvGrid1Tab2.FocusedRowIndex, "S_YONGHUH"));
           // loadQuanNian2(yonghuh);
        }
        
        protected void BtnQN2_Click(object sender, EventArgs e)
        {
            // string yonghuh = Convert.ToString(this.gvGrid1Tab2.GetRowValues(this.gvGrid1Tab2.FocusedRowIndex, "S_YONGHUH"));
            //loadQuanNian2(yonghuh);
        }

        //private void loadQuanNian2(string yonghuh)
        //{
        //    //string yonghuh = Convert.ToString(this.gvGrid1Tab2.GetRowValues(this.gvGrid1Tab2.FocusedRowIndex, "S_YONGHUH"));
        //    DataTable dt = null;
        //    if (string.IsNullOrEmpty(yonghuh))
        //    {
        //        return;
        //    }
        //    yonghuh = string.IsNullOrEmpty(yonghuh) ? null : yonghuh;

        //    dt = SearchSpHelper.P_QS_CX_QUANNIANQKCX_DXS(1, Convert.ToInt32(this.cmbYear.Value), null, null, yonghuh, null, null, null, null, null, null, null, null, null, null, null, null, null).Tables[0];
        //    gvGrid2Tab2.Columns.Clear();
        //    LoadColumnDate(gvGrid2Tab2, "S_M", "月份", 80);
        //    LoadColumnDate(gvGrid2Tab2, "I1", "普通采", 90);
        //    LoadColumnDate(gvGrid2Tab2, "I2", "矿泉采", 90);
        //    LoadColumnDate(gvGrid2Tab2, "I3", "采灌采", 100);
        //    LoadColumnDate(gvGrid2Tab2, "I0", "开采量", 100);
        //    LoadColumnDate(gvGrid2Tab2, "J1", "采灌灌", 100);
        //    LoadColumnDate(gvGrid2Tab2, "J2", "专灌", 100);
        //    LoadColumnDate(gvGrid2Tab2, "J0", "回灌量", 120);
        //    LoadColumnDate(gvGrid2Tab2, "N0", "深井水费", 100, "0.00");

        //    dtGridTab2_2 = dt;
        //    gvGrid2Tab2.DataSource = dtGridTab2_2;
        //    gvGrid2Tab2.DataBind();
        //}
        #endregion

      

        private void LoadColumnDate(ASPxGridView gv, string fieldName, string caption, int width, string format)
        {
            GridViewDataTextColumn c = new GridViewDataTextColumn();
            c.FieldName = fieldName;
            c.Caption = caption;
            c.Width = width;
            c.PropertiesEdit.DisplayFormatString = format;
            gv.Columns.Add(c);
        }
        private void LoadColumnDate(ASPxGridView gv, string fieldName, string caption, int width)
        {
            GridViewDataTextColumn c = new GridViewDataTextColumn();
            c.FieldName = fieldName;
            c.Caption = caption;
            c.Width = width;
            gv.Columns.Add(c);
        }
        #endregion

      
       

        //protected void gvGrid2Tab2_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        //{
        //    string yonghuh = e.Parameters;
        //    loadQuanNian2(yonghuh);
        //}

        protected void btnExport_Click(object sender, EventArgs e)
        {
            gvGrid1Tab2.DataSource = dtGridTab2_1;
            gvGrid1Tab2.DataBind();
            ASPxGridViewExporter1.GridViewID = "gvGrid1Tab2";
            string sName = "全年用水情况";
            gvGrid1Tab2.Settings.ShowFooter = false;
            ASPxGridViewExporter1.WriteXlsToResponse(sName);

        }

        //protected void btnExport2_2_Click(object sender, EventArgs e)
        //{
        //    gvGrid2Tab2.DataSource = dtGridTab2_2;
        //    gvGrid2Tab2.DataBind();
        //    ASPxGridViewExporter1.GridViewID = "gvGrid2Tab2";
        //    string sName = "用户用水信息";
        //    gvGrid2Tab2.Settings.ShowFooter = false;
        //    ASPxGridViewExporter1.WriteXlsToResponse(sName);
        //}


    }
}